package com.example.educationblockchain.service;


import com.example.educationblockchain.entity.MongoTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MongoService {

    @Autowired
    private MongoTemplate mongoTemplate;

    public List<MongoTest> findAll() {
        return mongoTemplate.findAll(MongoTest.class);
    }

    public List<MongoTest> findTestByX(double x) {
        Query query = new Query(Criteria.where("x").is(x));
        List<MongoTest> users = mongoTemplate.find(query, MongoTest.class);
        return users;
    }

    public void saveTest(MongoTest mongoTest){
        mongoTemplate.save(mongoTest);
    }


}
